package prv.pursuivant.unimportant.scraps;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.StringTokenizer;

import prv.pursuivant.config.CategorySerializer;
import prv.pursuivant.config.impl.XStreamCategorySerializerModule;
import prv.pursuivant.core.AchievType;
import prv.pursuivant.core.AchievTypesTree;

import com.google.inject.Guice;
import com.google.inject.internal.Lists;

public class WordBreaks {

	@SuppressWarnings("unused")
	private final String[] args;

	public WordBreaks(String[] args) {
		this.args = args;
	}

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		new WordBreaks(args).start();
	}

	private void start() throws IOException {
		CategorySerializer serializer = Guice.createInjector(
				new XStreamCategorySerializerModule()).getInstance(
				CategorySerializer.class);
		AchievTypesTree tree = serializer.readTree(new FileInputStream(
				"config/category.168.xml"));
		Collection<String> names = Lists.newArrayList();
		addToSet(names, tree, tree.getRoot());
		for (String name : names)
			System.out.println(name + "=" + name);
	}

	private void addToSet(Collection<String> names, AchievTypesTree tree,
			AchievType achiev) {
		StringTokenizer tokenizer = new StringTokenizer(achiev.getName());
		while (tokenizer.hasMoreTokens()) {
			String token = tokenizer.nextToken();
			if (token.length() > 5 && !names.contains(token))
				names.add(token);
		}
		for (String crit : achiev.getCriteria())
			addToSet(names, tree, tree.findAchievTypeById(crit));
	}

}
